// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using NUnit.Framework;
using ValidationAspects.Core;
using ValidationAspects.Exceptions;

namespace TestValidationAspects.Core
{
	[TestFixture]
	public class TestCast
	{
		[Test]
		public void Test_Cast_throws_for_invalid_cast()
		{
			Test.Throws<UnsupportedValidationException, InvalidCastException>(() => Cast<double>.From("text"),
			                                                                  string.Format("Failed to cast [type:{0}] to [type:{1}] for validation.", typeof(string), typeof(double)));
		}

		[Test]
		public void Test_Cast_succeeds_for_same_types()
		{
			const string from = "text";
			string s = Cast<string>.From(from);

			Assert.AreSame(from, s);
		}

		[Test]
		public void Test_Cast_succeeds_for_casting_to_base_type()
		{
			Derived derived = new Derived();
			Base b = Cast<Base>.From(derived);

			Assert.AreSame(derived, b);
		}

		#region Mocks
		public class Base {}

		public class Derived : Base {}
		#endregion
	}
}